pico-8 cartridge // http://www.pico-8.com
version 36
__lua__
--fill patterns
--patreon.com/mboffin

--note: this cart is intended 
--to be run and the resulting 
--tool used as a reference. 
--the code below isn't commented
--simply because its only
--purpose is to draw what is 
--shown when the cart is run.

function _init()
 --fill pattern
 p="0b0000000000000000"
 trans=false
	c1,c2=9,10 --colors
	crsr=0
end

function _update()
 --move bit cursor
	if (btnp(0)) then crsr=(crsr+15)%16 end
	if (btnp(1)) then crsr=(crsr+1)%16 end
	if (btnp(2)) then crsr=(crsr+12)%16 end
	if (btnp(3)) then crsr=(crsr+4)%16 end

 --bit flipping
	if (btnp(4)) then
		p=sub(p,1,2+crsr)..(sub(p,3+crsr,3+crsr)=="0" and "1" or "0")..sub(p,4+crsr)
	end
	
	--opaque/transparent
	if (btnp(5)) then trans=not trans end
end

function _draw()
	cls()
	draw_function(14,4)
	draw_grid(5,21)
	draw_instructions(50,25)
	draw_examples(5,70)
end


-->8
--display functions

function draw_function(x,y)

 --quartet markers
 for i=0,3 do
  rect(x+32+i*16,y,x+46+i*16,y+1,flr(crsr/4)==i and 7 or 5)
 	line(x+33+i*16,y+1,x+45+i*16,y+1,0)
 end

 --function
	print("fillp("..p..(trans and ".1)" or ")"),x,y+3,6)

	--bit marker
	pset(x+33+crsr*4,y+9,btn(4) and 10 or 5)
	line(x+32+crsr*4,y+10,x+34+crsr*4,y+10,btn(4) and 10 or 5)
	line(x+31+crsr*4,y+11,x+35+crsr*4,y+11,btn(4) and 10 or 5)
end

function draw_grid(gx,gy)
	
	--bit grid
	for i=0,3 do for j=0,3 do
	 rect(gx+i*10,gy+j*10,gx+i*10+10,gy+j*10+10,1)
	 print(sub(p,3+j*4+i,3+j*4+i),gx+i*10+4,gy+j*10+3,sub(p,3+j*4+i,3+j*4+i)=="0" and c2 or c1)
	end end
	
	--current bit box
	rect(gx+(crsr%4)*10,gy+flr(crsr/4)*10,gx+(crsr%4)*10+10,gy+flr(crsr/4)*10+10,7)

end

function draw_instructions(x,y)
	print("  select:",x,y,6)
	print("          <-", x, y, btn(0) and 10 or 5)
	print("            ->",x,y, btn(1) and 10 or 5)
	print("             up",x,y,btn(2) and 10 or 5)
	print("                down", x, y, btn(3) and 10 or 5)
	print("flip bit:",x,y+7,6)
	print("          o",x,y+7,btn(4) and 10 or 5)
	print("  opaque:",x,y+14,trans and 5 or 6)
	print("          x",x,y+14,btn(5) and 10 or 5)

	print("   color: ",x,y+28,6)
	print("          0x",x,y+28,6)
	print("            "..hexs(c1),x,y+28,c1)
	print("             "..hexs(c2),x,y+28,c2)
end

function draw_examples(x,y)
	local w,h=24,24
	local c=16*c1+c2

	fillp(tonum(p..(trans and ".1" or "")))

 --rect/rectfill
 print("rect()\nrectfill()",x,y+h+16,6)
	rect(x,y,x+w+6,y+h+6,c)
	rectfill(x+3,y+3,x+w+3,y+h+3,c)
	
	--circ/circfill
 print("circ()\ncircfill()",x+45,y+h+16,6)
	circ(x+60,y+h/2+3,h/2+3,c)
	circfill(x+60,y+h/2+3,h/2,c)

 --pset/line
 print("pset()\nline()",x+90,y+h+16,6)
 line(x+90,y,x+114,y+h/3,c)
 line(x+90,y+h/2,x+114,y+h+6,c)
 line(x+90,y+h+6,x+114,y,c)
 line(x+90,y+h/2,x+114,y+h/2,c)
 srand(2)
 for i=1,30 do
 	pset(x+90+rnd(w+6),y+rnd(h+6),c)
 end
 
	fillp()
end

--convert single digit to hex
function hexs(a)
 local s={[0]=0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"}
	return s[a%16]
end
__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__label__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000007777777777777770555555555555555055555555555555505555555555555550000000000000000000
00000000000000000000000000000000000000000000007000000000000070500000000000005050000000000000505000000000000050000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000666066606000600066600600666066606660660066606600660066006660660066606660666066006600660066006600060000000000000000
00000000000000600006006000600060606000606060606060060060600600060006006060060060606060606006000600060006000600006000000000000000
00000000000000660006006000600066606000606066006060060060600600060006006060060060606060606006000600060006000600006000000000000000
00000000000000600006006000600060006000606060606060060060600600060006006060060060606060606006000600060006000600006000000000000000
00000000000000600066606660666060000600666066606660666066606660666066606660666066606660666066606660666066606660060000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000005550000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000055555000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000777777777771111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000700000000070000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000700000000070000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000007000aaa00070009900001000aaa000100099000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000007000a0a00070000900001000a0a000100009000010000000000000660666060006660066066600000000005555500055555000555550005555500000000
000007000a0a00070000900001000a0a000100009000010000000000006000600060006000600006000600000055500550550055505550555055000550000000
000007000a0a00070000900001000a0a000100009000010000000000006660660060006600600006000000000055000550550005505500055055000550000000
000007000aaa00070009990001000aaa000100099900010000000000000060600060006000600006000600000055500550550055505500055055505550000000
00000700000000070000000001000000000100000000010000000000006600666066606660066006000000000005555500055555000555550005555500000000
00000700000000070000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000777777777771111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000666060006660666000006660666066600000000005555500000000000000000000000000000000
00000100000000010000000001000000000100000000010000600060000600606000006060060006000600000055000550000000000000000000000000000000
00000100099000010009900001000aaa000100099000010000660060000600666000006600060006000000000055050550000000000000000000000000000000
00000100009000010000900001000a0a000100009000010000600060000600600000006060060006000600000055000550000000000000000000000000000000
00000100009000010000900001000a0a000100009000010000600066606660600000006660666006000000000005555500000000000000000000000000000000
00000100009000010000900001000a0a000100009000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100099900010009990001000aaa000100099900010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000000660666066600600606066600000000005555500000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000006060606060606060606060000600000055050550000000000000000000000000000000
00000111111111111111111111111111111111111111110000000000006060666066606060606066000000000055505550000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000006060600060606600606060000600000055050550000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000006600600060600660066066600000000005555500000000000000000000000000000000
000001000aaa0001000aaa0001000aaa000100099000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001000a0a0001000a0a0001000a0a000100009000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001000a0a0001000a0a0001000a0a000100009000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001000a0a0001000a0a0001000a0a000100009000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001000aaa0001000aaa0001000aaa000100099900010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
000001000000000100000000010000000001000000000100000000000000000660066060000660666000000000666060609990aaa00000000000000000000000
000001000990000100099000010009900001000990000100000000000000006000606060006060606006000000606060609090a0a00000000000000000000000
000001000090000100009000010000900001000090000100000000000000006000606060006060660000000000606006009990aaa00000000000000000000000
000001000090000100009000010000900001000090000100000000000000006000606060006060606006000000606060600090a0a00000000000000000000000
000001000090000100009000010000900001000090000100000000000000000660660066606600606000000000666060600090a0a00000000000000000000000
00000100099900010009990001000999000100099900010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000010000000001000000000100000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000aa9aaa9aaa9aaa9aaa9aaa9aaa9aaa900000000000000000000000000a9aaa9a000000000000000000000000009a0000000000000000000000900000000
00000900000000000000000000000000000900000000000000000000000999000000099900000000000000000000000009990000000000000000009000000000
0000090000000000000000000000000000090000000000000000000009a0000000000000a900000000000000000000000000a9a0000000000000090000000000
0000090099a999a999a999a999a999a9900900000000000000000000900000a999a9900000a00000000000000000000000a00009990000000000090000000000
00000a00aaa9aaa9aaa9aaa9aaa9aaa9a009000000000000000000090000aaa9aaa9aaa00009000000000000000000000000000000a9a0090000a0000a000000
00000900999999999999999999999999900900000000000000000090009999999999999990009000000000000000000000000000000009990009000000000000
00000900a9a9a9a9a9a9a9a9a9a9a9a9a0090000000000000000090009a9a9a9a9a9a9a9a900090000000000000000000000000000000000a9a9000000000000
0000090099a999a999a999a999a999a990090000000000000000900099a999a999a999a999a000a0000000000000000009000000000900000909990000000000
00000a00aaa9aaa9aaa9aaa9aaa9aaa9a0090000000000000000a009aaa9aaa9aaa9aaa9aaa900a0000000000000000000000000000000000a0000a900000000
00000900999999999999999999999999900900000000000000090009999999999999999999990009000000000000000000000000000000009000900000000000
00000900a9a9a9a9a9a9a9a9a9a9a9a9a009000000000000000900a9a9a9a9a9a9a9a9a9a9a9a009000000000000000000000000000000090000000000000000
0000090099a999a999a999a999a999a99009000000000000000900a999a999a999a999a999a990090000000000000000000000a0000000a00000000009000000
00000a00aaa9aaa9aaa9aaa9aaa9aaa9a00900000000000000a00aa9aaa9aaa9aaa9aaa9aaa9aa00a000000000000009aaa9aaa9aaa9aaa9aaa9aaa900000000
00000900999999999999999999999999900900000000000000900999999999999999999999999900900000000000000090000000000009000000000000000000
00000900a9a9a9a9a9a9a9a9a9a9a9a9a00900000000000000a009a9a9a9a9a9a9a9a9a9a9a9a900a00000000000000009a000000000a0000009000000000000
0000090099a999a999a999a999a999a9900900000000000000a009a999a999a999a999a999a99900900000000000000000090000000900000000000000000000
00000a00aaa9aaa9aaa9aaa9aaa9aaa9a00900000000000000a00aa9aaa9aaa9aaa9aaa9aaa9aa00a0000000000000000000a00000a000000000000000000000
00000900999999999999999999999999900900000000000000900999999999999999999999999900900000000000000900000990090000000000000000000000
00000900a9a9a9a9a9a9a9a9a9a9a9a9a00900000000000000a009a9a9a9a9a9a9a9a9a9a9a9a900a00000000000000000000009090000000000000000000000
0000090099a999a999a999a999a999a99009000000000000000900a999a999a999a999a999a99009000000000000000000000000900000000000000000000000
00000a00aaa9aaa9aaa9aaa9aaa9aaa9a009000000000000000900a9aaa9aaa9aaa9aaa9aaa9a0090000000000000000000000090aa900000000000000000000
00000900999999999999999999999999900900000000000000090009999999999999999999990009000000000000000000000090000900009000000000000000
00000900a9a9a9a9a9a9a9a9a9a9a9a9a0090000000000000000a009a9a9a9a9a9a9a9a9a9a900a00000000000000000000009000000a0000000000000000000
0000090099a999a999a999a999a999a990090000000000000000900099a999a999a999a999a000a0000000000000000090a00900090009a00000000000000000
00000a00aaa9aaa9aaa9aaa9aaa9aaa9a00900000000000000000a000aa9aaa9aaa9aaa9aa000a0000000000000000000000a0a0000000090a00000000000000
00000900999999999999999999999999900900000000000000000090009999999999999990009000000000000000000000090090000000009900090000000000
00000900a9a9a9a9a9a9a9a9a9a9a9a9a009000000000000000000090000a9a9a9a9a9a000090000000000000000000000a000000000000009a0000009000000
0000090099a999a999a999a999a999a9900900000000000000000000900000a999a9900000a00000000000000000000099000900000000000909000000000000
00000a000000000000000000000000000009000000000000000000000aa0000000000000aa00000000000000000000000a000000000000000000a00000000000
00000900000000000000000000000000000900000000000000000000000999000000099900000000000000000000000090000000000000000000099000900000
000009a9a9a9a9a9a9a9a9a9a9a9a9a9a9a900000000000000000000000000a9a9a9a00000000000000000000000000900000000000000000000000900000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000666066600660666006000600000000000000000000000066066606660066006000600000000000000000000000666006606660666006000600000000000
00000606060006000060060000060000000000000000000000600006006060600060000060000000000000000000000606060006000060060000060000000000
00000660066006000060060000060000000000000000000000600006006600600060000060000000000000000000000666066606600060060000060000000000
00000606060006000060060000060000000000000000000000600006006060600060000060000000000000000000000600000606000060060000060000000000
00000606066600660060006000600000000000000000000000066066606060066006000600000000000000000000000600066006660060006000600000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000666066600660666066606660600060000600060000000066066606660066066606660600060000600060000000600066606600666006000600000000000
00000606060006000060060000600600060006000006000000600006006060600060000600600060006000006000000600006006060600060000060000000000
00000660066006000060066000600600060006000006000000600006006600600066000600600060006000006000000600006006060660060000060000000000
00000606060006000060060000600600060006000006000000600006006060600060000600600060006000006000000600006006060600060000060000000000
00000606066600660060060006660666066600600060000000066066606060066060006660666066600600060000000666066606060666006000600000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

